$( document ).on( "pageshow", "#freshNews", function( event ) {
});
$( document ).on( "pagecreate", "#freshNews", function( event ) {
	access_token=getQueryString("access_token");

	pageNo="1";
	pageSize="10";
	document.getElementById("wrapper_freshNews").style.bottom="0px";
	$("#wrapper_freshNews  #pullDown").hide();
	$("#wrapper_freshNews  #pullUp").hide();
	
	var scrollObj_freshNews=scrollPlugLoadedOfReturn_new("wrapper_freshNews",
				function() {
					setTimeout(function () {
						if(pageNo >= totalPage)
							return;
						pageNo++;
						loadData_freshNews(false,scrollObj_freshNews);
					}, 1000);	
				},
				function() {
					setTimeout(function () {
						if(pageNo>1){
							pageNo--;
							loadData_freshNews(true,scrollObj_freshNews);
							if(pageNo==1){
								$("#wrapper_freshNews  #pullDown").hide();
							}
						}
					}, 1000);
				});
		
	loadData_freshNews(true,scrollObj_freshNews);
});

function p_show(obj){
	var c = $(obj).css("white-space");
	if(c == 'normal'){
		$(obj).css({"white-space":"nowrap"});
	}else{
		$(obj).css({"white-space":"normal"});
	}	
}

/**
 * 
 * @param isFresh 是否刷新
 * @param isFresh 是否初始列表
 */
function loadData_freshNews(isFresh,scrollObj_freshNews){
	showLoading();
	$.ajax({
	  	url: rootPath+"/review/freshNews.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&pageNo="+pageNo+"&pageSize="+pageSize,
	  	success: function( response ) {
	  		hideLoading();
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				 totalPage=data.data.totalPage;
		  		var totalRow=data.data.totalRow;
		  		var arr=data.data.rows;
				var content = "";
				for (var i=0;i<arr.length;i++){
					var headerPic=rootPath+defaultHeadPic;
					//当头像不为空时，校验评论类型是否为0（实名）
					if(arr[i].criticsHeadImgUrl!=undefined && arr[i].criticsHeadImgUrl!="" && arr[i].criticsType=="0")
						headerPic=arr[i].criticsHeadImgUrl;
					var reviewName="匿名";
					if(arr[i].criticsType=="0")
						reviewName=arr[i].criticsName;
					if(arr[i].reviewType=="4"){//抽奖
						content +='<li data-icon="false">\
							  <a href="#"  '+comStyle+'>\
								<img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon">\
								<p '+margin_top_no+'><span style="font-size:15px;">\
									<span class="text_strong">#幸运大转盘#</span></span>\
									<strong class="ui-li-aside_fresh_new" '+sideStyle+' >'+arr[i].create_timeStr+'</strong>\
								</p>\
								<p '+margin_top_6+' onclick="p_show(this)" >'+replaceContent(arr[i].reviewContent)+'</p>\
							  </a>\
						</li>';
					}else if(arr[i].reviewType=="5"){//押宝
						content +='<li data-icon="false">\
							  <a href="#"  '+comStyle+'>\
								<img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon">\
								<p '+margin_top_no+'><span style="font-size:15px;">\
								#谁是红花王#</span></span>\
									<strong class="ui-li-aside_fresh_new" '+sideStyle+' >'+arr[i].create_timeStr+'</strong>\
								</p>\
								<p '+margin_top_6+' onclick="p_show(this)" >'+replaceContent(arr[i].reviewContent)+'</p>\
							  </a>\
						</li>';
					}else{
						content +='<li data-icon="false">\
									  <a href="#"  '+comStyle+'>\
										<img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon">\
										<p '+margin_top_no+'><span style="font-size:15px;">\
											<span class="text_strong">'+reviewName+'</span> 送给 <span class="text_strong">'+arr[i].byCriticsName+'</span> \
											 <img style="width:18px;height:18px" src="'+rootPath+flower_+'"/>\</span>\
											<strong class="ui-li-aside_fresh_new" '+sideStyle+' >'+arr[i].create_timeStr+'</strong>\
										</p>\
										<p '+margin_top_6+' onclick="p_show(this)" >'+replaceContent(arr[i].reviewContent)+'</p>\
									  </a>\
								</li>';
					}
				}
				if(arr.length<pageSize){
					$("#wrapper_freshNews  #pullUp").hide();
				}else{
					$("#wrapper_freshNews  #pullUp").show();
				}
				if(isFresh)
					$("#thelist_freshNews").html("");
				
				//页数是2的倍数时，清空缓存列表
				if(pageNo%3==0){
					$("#wrapper_freshNews  #pullDown").show();
					$("#thelist_freshNews").html("");
					$("#thelist_freshNews").append(content).listview('refresh');
				}else{
					$("#thelist_freshNews").append(content).listview('refresh');
				}
				scrollObj_freshNews.refresh();
			}else{
				alert_wx('fail',data.msg);
			}
	  	}
	});
}
